package com.ruoyi.web.controller.region;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.domain.entity.SysMenu;
import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.construction.domain.ConstructionSite;
import com.ruoyi.four.FourPlatformService;
import com.ruoyi.region.domain.TSysCity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.region.domain.TSysArea;
import com.ruoyi.region.service.ITSysAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 地区设置Controller
 * 
 * @author ruoyi
 * @date 2024-12-14
 */
@RestController
@RequestMapping("/region/area")
public class TSysAreaController extends BaseController
{
    @Autowired
    private ITSysAreaService tSysAreaService;


    @Autowired
    private FourPlatformService fourPlatformService;

    /**
     * 查询地区设置列表
     */
    @PreAuthorize("@ss.hasPermi('region:area:list')")
    @GetMapping("/list")
    public TableDataInfo list(TSysArea tSysArea)
    {
        startPage();
        List<TSysArea> list = tSysAreaService.selectTSysAreaList(tSysArea);
        return getDataTable(list);
    }
    /**
     * 查询区域列表
     */
    @GetMapping("/selectAreaList")
    public AjaxResult selectAreaList(String cityCode)
    {
        TSysArea tSysArea = new TSysArea();
        tSysArea.setCityCode(cityCode);
        List<TSysArea> list = tSysAreaService.selectTSysAreaList(tSysArea);
        return AjaxResult.success(list);
    }
    /**
     * 导出地区设置列表
     */
    @PreAuthorize("@ss.hasPermi('region:area:export')")
    @Log(title = "地区设置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TSysArea tSysArea)
    {
        List<TSysArea> list = tSysAreaService.selectTSysAreaList(tSysArea);
        ExcelUtil<TSysArea> util = new ExcelUtil<TSysArea>(TSysArea.class);
        util.exportExcel(response, list, "地区设置数据");
    }

    /**
     * 获取地区设置详细信息
     */
    @PreAuthorize("@ss.hasPermi('region:area:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tSysAreaService.selectTSysAreaById(id));
    }

    /**
     * 新增地区设置
     */
    @PreAuthorize("@ss.hasPermi('region:area:add')")
    @Log(title = "地区设置", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TSysArea tSysArea)
    {
        return toAjax(tSysAreaService.insertTSysArea(tSysArea));
    }

    /**
     * 修改地区设置
     */
    @PreAuthorize("@ss.hasPermi('region:area:edit')")
    @Log(title = "地区设置", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TSysArea tSysArea)
    {
        return toAjax(tSysAreaService.updateTSysArea(tSysArea));
    }

    /**
     * 删除地区设置
     */
    @PreAuthorize("@ss.hasPermi('region:area:remove')")
    @Log(title = "地区设置", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tSysAreaService.deleteTSysAreaByIds(ids));
    }


    /**
     * 通用地域列表
     */
    @GetMapping("/regionAreaList")
    public AjaxResult regionAreaList()
    {
        List<Map<String,Object>> list = tSysAreaService.regionAreaList();
        return AjaxResult.success(list);
    }


    /**
     *  测试项目
     */
    @PostMapping("/addProject")
    public AjaxResult addProject(@RequestBody ConstructionSite constructionSite)
    {
//        LoginUser loginUser = getLoginUser();
//        String sessionId = loginUser.getSessionId();
//        String sessionId = "s0ERhlmMhdTYvYmN2VGKxYGYiV2ciVnMqhDKgRmNlZCNulDa3Y2YuR2X18lN3ITSxM0MthTQ6MVOPdjT0ckMAZmX5k3MmQWc2IHNfN2X1ImYlNDZ102NfV2XnRTYiFGYiB2a182MoBDK4gHMtJTciR2YMNGUxIjNZJTakNDOY";
        String sessionId = "s0ERhlmMhdTYvYmN2VGKxYGYiV2ciVnMqhDKgRmNlZCNulDa3Y2YuR2X18lN3ITSxM0MthTQ6MVOPdjT0ckMAZmX5k3MmQWc2IHNfN2X1ImYlNDZ102NfV2XnRTYiFGYiB2a182MoBDK4gHMtJTciR2YMNGUxIjNZJTakNDOY";
        String s = fourPlatformService.addPoi(constructionSite,sessionId);
        return AjaxResult.success(s);
    }
}
